package com.pft.web.view.dialog;

import android.app.Activity;

/**
 * @author lijianqing
 */

public final class DialogManager {

    private DialogManager() {

    }

    /**
     * 显示一个温馨提示的Dialog
     *
     * @param activity    你懂的
     * @param contentText 提示文字
     * @return 显示了一个dialog
     */
    public static BaseDialog showAlertDialog(Activity activity, CharSequence contentText) {
        return showAlertDialog(activity, contentText, true, null);
    }

    /**
     * 显示确定一个按钮的弹框
     *
     * @param activity
     * @param contentText
     * @param listener
     * @return
     */
    public static BaseDialog showAlertDialog(Activity activity, CharSequence contentText,
                                             AlertDialog.OnButtonClickListener listener) {
        return showAlertDialog(activity, contentText, true, listener);
    }

    /**
     * 显示确定一个按钮的弹框
     *
     * @param activity
     * @param contentText
     * @param cancelable
     * @param listener
     * @return
     */
    public static BaseDialog showAlertDialog(Activity activity, CharSequence contentText, boolean cancelable,
                                             AlertDialog.OnButtonClickListener listener) {
        return showAlertDialog(activity, null, contentText, null, cancelable, listener);
    }

    /**
     * 显示确定一个按钮的弹框
     *
     * @param activity
     * @param titleText
     * @param contentText
     * @param alertText
     * @param cancelable
     * @param listener
     * @return
     */
    public static BaseDialog showAlertDialog(Activity activity, String titleText, CharSequence contentText,
                                             String alertText, boolean cancelable,
                                             AlertDialog.OnButtonClickListener listener) {
        final AlertDialog alertDialog = new AlertDialog(activity);
        alertDialog.setTitleText(titleText);
        alertDialog.setContentText(contentText);
        alertDialog.setAlertText(alertText);

        alertDialog.setCancelable(cancelable);
        alertDialog.setCanceledOnTouchOutside(cancelable);

        alertDialog.setButtonClickListener(listener);

        alertDialog.show(activity);

        return alertDialog;
    }

    /**
     * 显示确定、取消两个按钮的弹框
     *
     * @param activity
     * @param contentText
     * @param listener
     * @return
     */
    public static BaseDialog showConfirmDialog(Activity activity, CharSequence contentText,
                                               ConfirmDialog.OnButtonClickListener listener) {
        return showConfirmDialog(activity, contentText, true, listener);
    }

    /**
     * 显示确定、取消两个按钮的弹框
     *
     * @param activity
     * @param contentText
     * @param cancelable
     * @param listener
     * @return
     */
    public static BaseDialog showConfirmDialog(Activity activity, CharSequence contentText, boolean cancelable,
                                               ConfirmDialog.OnButtonClickListener listener) {
        return showConfirmDialog(activity, null, contentText, null, null, cancelable, listener);
    }



    /**
     * 显示确定、取消两个按钮的弹框
     *
     * @param activity
     * @param titleText
     * @param contentText
     * @param cancelText
     * @param confirmText
     * @param cancelable
     * @param listener
     * @return
     */
    public static BaseDialog showConfirmDialog(Activity activity, String titleText, CharSequence contentText,
                                               String cancelText, String confirmText, boolean cancelable,
                                               ConfirmDialog.OnButtonClickListener listener) {
        final ConfirmDialog confirmDialog = new ConfirmDialog(activity);
        confirmDialog.setTitleText(titleText);
        confirmDialog.setContentText(contentText);
        confirmDialog.setCancelText(cancelText);
        confirmDialog.setConfirmText(confirmText);

        confirmDialog.setCancelable(cancelable);
        confirmDialog.setCanceledOnTouchOutside(cancelable);

        confirmDialog.setButtonClickListener(listener);

        confirmDialog.show(activity);

        return confirmDialog;
    }


}
